<template>
  <div class="app-container">
    <div
      style="
        margin-right: auto;
        margin-left: auto;
        width: 600px;
        border: 1px solid #aaa;
        padding: 50px 30px;
        margin-top: 100px;
      "
    >
      <el-form label-width="110px" :model="list">
        <el-form-item label="商户ID">
          <el-input v-model="list.id"></el-input>
        </el-form-item>
        <el-form-item label="商户名称">
          <el-input v-model="list.merchant_name"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="list.phone"></el-input>
        </el-form-item>
        <el-form-item label="电池回调地址">
          <el-input v-model="list.notify_url"></el-input>
        </el-form-item>
        <el-form-item label="商户密钥">
          <el-input v-model="list.api_key"></el-input>
        </el-form-item>
      </el-form>
      <div style="margin-top: 40px; text-align: center">
        <el-button
          class="filter-item"
          size="medium"
          type="primary"
          icon="el-icon-plus"
          @click="editConfirmFn"
        >
          保存
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { urlObj } from "@/api/login";
export default {
  data() {
    return {
      list: {}, //商户信息数据
    };
  },
  mounted() {
    this.listFn(JSON.parse(sessionStorage.getItem("userObj")).mer_id);
  },
  methods: {
    // 保存
    editConfirmFn(val) {
      let prarms = {
        func: "setMerchant",
        token: JSON.parse(sessionStorage.getItem("userObj")).token || "",
        business: this.list,
      };
      urlObj(prarms)
        .then((res) => {
          this.listFn(JSON.parse(sessionStorage.getItem("userObj")).mer_id);
          this.$message({
            message: res.msg || "",
            type: res.code == 0 ? "success" : "error",
          });
        })
        .catch((error) => {
          this.$message({
            message: res.msg || "",
            type: "error",
          });
        });
    },
    // 列表数据
    listFn(id) {
      let prarms = {
        func: "getMerchants",
        token: JSON.parse(sessionStorage.getItem("userObj")).token || "",
        business: { id: id ? id : "" },
      };
      urlObj(prarms).then((res) => {
        this.list = res.result[0] || {};
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
